<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 配置数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\OptionsService;
use think\Request;
use think\Response;

class OptionsController extends VerifyController
{
    /**
     * @var \common\service\OptionsService
     */
    protected $optionsService;

    public function __construct()
    {
        parent::__construct();
        $this->optionsService = new OptionsService();
    }

    /**
     * 添加配置
     * @param Request $request
     * @return \think\Response
     */
    public function create(Request $request)
    {
        $param = $request->param();
        $resData = $this->optionsService->addOptionsData($param['data']);
        return json($resData);
    }

    /**
     * 修改options
     * @param Request $request
     * @return \think\Response
     */
    public function update(Request $request)
    {
        try {
            $param = $request->param();
            $resData = $this->optionsService->updateOptionsData($param['data']);
            return json($resData);
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 获取媒体指定上传服务器配置信息
     * @param Request $request
     * @return \think\Response
     */
    public function getMediaUploadServer(Request $request)
    {
        $resData = $this->optionsService->getMediaUploadServer();
        return json(success_response('', $resData));
    }

    /**
     * 获取日志服务器配置信息
     * @param Request $request
     * @return \think\Response
     */
    public function getEventLogServer(Request $request)
    {
        $resData = $this->optionsService->getEventLogServer();
        return json(success_response('', $resData));
    }

    /**
     * 获取合同业务模式配置
     * @return \think\Response
     */
    public function getBusinessMode(){
        $resData = $this->optionsService->getBusinessMode();
        return json(success_response('', $resData));
    }

    /**
     * 服务列表接口
     * @return Response
     * @throws \Exception
     */
    public function getServiceList(){
        $resData = $this->optionsService->getServiceList();
        return json(success_response('', $resData));
    }
}
